import { Toast, Dialog } from "vant";
import cTitle from "components/title";
import goodsCard from "../consumptionComm/goodsCard/goodsCard";
import purchaseNotes from "../consumptionComm/purchaseNotes/purchaseNotes";
export default {
  components: {
    goodsCard,
    purchaseNotes,
    cTitle
  },
  data() {
    return {
      couponSn: "",
      buyNotice: [],
      packageDetail: [],
      noticeDesc: "",
      priceDesc: "",
      storeId: "",
      offlinePrice: 0,
      orderGoods: {},
      pluginSetting: {}
    };
  },
  activated() {
    this.storeId = Number(this.$route.query.storeId);
    this.couponSn = this.$route.query.couponSn;
    this.examineCoupon();
  },
  mounted() {},
  methods: {
    examineCoupon() {
      let json = {
        cstore_id: this.storeId,
        coupon_sn: this.couponSn,
        request_type: 1,
        basic_info: 1
      };
      $http.post("plugin.coupon-store.frontend.store-manage.examineCoupon", json, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.orderGoods = res.order_goods;
            this.offlinePrice = res.offline_price;
            this.buyNotice = res.buy_notice;
            this.packageDetail = res.package_detail;
            this.noticeDesc = res.notice_desc;
            this.priceDesc = res.price_desc;
            this.pluginSetting = response.basic_info?.plugin_setting?.coupon_store || {};
          } else {
            // this.$dialog.alert({ message: response.msg });
            Toast(response.msg);
            setTimeout(() => {
              this.$router.go(-1);
            }, 1000);
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    onRefund(id) {
      if (id) {
        Dialog.confirm({
          title: "提示",
          message: `是否确认核销消费券号：${this.couponSn}`
        })
          .then(() => {
            let json = {
              cstore_id: this.storeId,
              coupon_sn: this.couponSn,
              request_type: 2
            };
            $http.post("plugin.coupon-store.frontend.store-manage.examineCoupon", json, "正在获取").then(
              response => {
                Toast(response.msg);
                setTimeout(() => {
                  this.$router.go(-1);
                }, 1000);
              },
              function(response) {
                // console.log(response);
                // error callback
              }
            );
          })
          .catch(() => {
            // on cancel
          });
      } else {
        Dialog.alert({
          message: "不是适用门店暂时不能核销"
        }).then(() => {
          // on confirm
          this.$router.go(-1);
        });
      }
    }
  }
};
